package com.icoopoo.common.base.icoopoo.core.security.coder;

import java.security.MessageDigest;

/**
 * @Auther: icoopoo@163.com
 * @Date: 2018/4/26 0026
 * @Description:
 */
public abstract class MDCoder extends SecurityCoder {
    public MDCoder() {
    }

    public static byte[] encodeMD2(byte[] data) throws Exception {
        MessageDigest md = MessageDigest.getInstance("MD2");
        return md.digest(data);
    }

    public static byte[] encodeMD4(byte[] data) throws Exception {
        MessageDigest md = MessageDigest.getInstance("MD4");
        return md.digest(data);
    }

    public static byte[] encodeMD5(byte[] data) throws Exception {
        MessageDigest md = MessageDigest.getInstance("MD5");
        return md.digest(data);
    }

    public static byte[] encodeTiger(byte[] data) throws Exception {
        MessageDigest md = MessageDigest.getInstance("Tiger");
        return md.digest(data);
    }

    public static String encodeTigerHex(byte[] data) throws Exception {
        byte[] b = encodeTiger(data);
        return new String(Hex.encode(b));
    }

    public static byte[] encodeWhirlpool(byte[] data) throws Exception {
        MessageDigest md = MessageDigest.getInstance("Whirlpool");
        return md.digest(data);
    }

    public static String encodeWhirlpoolHex(byte[] data) throws Exception {
        byte[] b = encodeWhirlpool(data);
        return new String(Hex.encode(b));
    }

    public static byte[] encodeGOST3411(byte[] data) throws Exception {
        MessageDigest md = MessageDigest.getInstance("GOST3411");
        return md.digest(data);
    }

    public static String encodeGOST3411Hex(byte[] data) throws Exception {
        byte[] b = encodeGOST3411(data);
        return new String(Hex.encode(b));
    }
}